/** 
 * Project Name:jd-orm 
 * File Name:GenerateIdUtil.java 
 * Package Name:com.jd.orm.framework.core.util 
 * Date:2014-5-13下午4:41:00 
 * Copyright (c) 2014, liubing1@jd.com All Rights Reserved. 
 * 
 */  

package com.jd.orm.framework.core.util;

import com.jd.orm.framework.core.keyid.JdbcSequenceIdProvider;
import com.jd.orm.framework.core.keyid.SequenceIdProvider;

/** 
 * ClassName: GenerateIdUtil <br/> 
 * Function: TODO ADD FUNCTION. <br/> 
 * Reason: TODO ADD REASON. <br/> 
 * date: 2014-5-13 下午4:41:00 <br/> 
 * 
 * @author  liubing1@jd.com 
 * @version  
 * @since up JDK 1.5 
 */

public class GenerateIdUtil {
	
	/**
	 * 
	 * generateKeyId: <br/> 
	 * TODO.<br/> 
	 * @author liubing1@jd.com
	 * @param tablename
	 * @return 
	 * @since JDK 1.5
	 */
	public static Integer generateIntegerKeyId(String tablename){
		
		SequenceIdProvider sequenceIdProvider=new JdbcSequenceIdProvider();
		int i=sequenceIdProvider.create(tablename).nextVal();
		return i;
	}
	/**
	 * 
	 * generateKeyId: <br/> 
	 * TODO.<br/> 
	 * @author liubing1@jd.com
	 * @param tablename
	 * @param datasourceId
	 * @return 
	 * @since JDK 1.5
	 */
	public static Integer generateIntegerKeyId(String tablename,String datasourceId){
		SequenceIdProvider sequenceIdProvider=new JdbcSequenceIdProvider(datasourceId);
		int i=sequenceIdProvider.create(tablename).nextVal();
		return i;
	}
	/**
	 * 
	 * generateStringKeyId: <br/> 
	 * TODO.<br/> 
	 * @author liubing1@jd.com
	 * @param tablename
	 * @return 
	 * @since JDK 1.5
	 */
	public static String generateStringKeyId(String tablename){
		SequenceIdProvider sequenceIdProvider=new JdbcSequenceIdProvider();
		int i=sequenceIdProvider.create(tablename).nextVal();
		return i+"";
	}
	/**
	 * 
	 * generateStringKeyId: <br/> 
	 * TODO.<br/> 
	 * @author liubing1@jd.com
	 * @param tablename
	 * @param datasourceId
	 * @return 
	 * @since JDK 1.5
	 */
	public static Long generateLongKeyId(String tablename,String datasourceId){
		SequenceIdProvider sequenceIdProvider=new JdbcSequenceIdProvider(datasourceId);
		int i=sequenceIdProvider.create(tablename).nextVal();
		return Long.parseLong(i+"");
	}
	/**
	 * 
	 * generateLongKeyId: <br/> 
	 * TODO.<br/> 
	 * @author liubing1@jd.com
	 * @param tablename
	 * @return 
	 * @since JDK 1.5
	 */
	public static Long generateLongKeyId(String tablename){
		SequenceIdProvider sequenceIdProvider=new JdbcSequenceIdProvider();
		int i=sequenceIdProvider.create(tablename).nextVal();
		return Long.parseLong(i+"");
	}
}
